<template>
  <BasicModal
    v-bind="$attrs"
    title="表单预览"
    @register="register"
    @ok="handleSubmit"
    @cancel="handleCancel"
    :destroyOnClose="true"
    :minHeight="600"
    :width="800"
    ><BasicForm @register="registerForm" :schemas="schemasList"
  /></BasicModal>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form';

  const schemasList = ref<any>([]);

  // 定义提交事件
  const handleSubmit = () => {
    handleCancel();
  };
  const handleCancel = () => {
    closeModal();
  };
  // 基本属性
  const [registerForm, { setFieldsValue, resetFields }] = useForm({
    labelWidth: 110,
    colon: true,
    labelCol: { span: 6 },
    wrapperCol: { span: 18 },
    showActionButtonGroup: false,
  });
  // 定义弹窗是否可见
  const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
    setModalProps({ confirmLoading: false });
    resetFields();
    const result = Object.entries(data.dataList.propAndName).map(([key, value]) => ({
      field: key,
      label: value,
      component: 'Input',
      colProps: {
        span: 12,
      },
      componentProps: {
        disabled: true,
      },
    }));
    schemasList.value = result;
    setFieldsValue(data.dataList.propAndValue);
  });
</script>

<style lang="less" scoped></style>
